package com.ltu.model.request.base;

import java.util.HashMap;
import java.util.Map;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import com.ltu.model.request.CommonRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Sort.Direction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;

@SuppressWarnings("serial")
@Api(tags="分页属性，分页用到，可忽略")
public class PageReqData extends CommonRequest {
	
	@ApiModelProperty(value="分页数，从1开始，不传默认为1",required=false)
	@Min(value=1,message="pageNumber必须大于等于1")
	private Integer pageNumber = 1;
	
	@ApiModelProperty(value="每个页数大小，不传默认为20",required=false)
	@Min(value=1,message="pageSize必须大于等于1")
	private Integer pageSize = 20;
	
	@ApiModelProperty(value="排序字段，默认为id", notes = "多字段用英文逗号隔开，多字段排序必须对应多个升降序字段",required=false)
	private String sortType;
	
	@ApiModelProperty(value="降序desc、升序asc，默认为desc",required=false)
	private String sortOrder;

	public Integer getPageNumber() {
		if(pageNumber == null){
			pageNumber = 1;
		}
		return pageNumber;
	}

	public void setPageNumber(Integer pageNumber) {
		this.pageNumber = pageNumber;
	}

	public Integer getPageSize() {
		if(pageSize == null){
			pageSize = 20;
		}
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public String getSortType() {
		if(StringUtils.isBlank(sortType)){
			sortType = "id";
		}
		return sortType;
	}

	public void setSortType(String sortType) {
		this.sortType = sortType;
	}

	public String getSortOrder() {
		if(StringUtils.isBlank(sortOrder)){
			sortOrder = "desc";
		}
		return sortOrder;
	}

	public void setSortOrder(String sortOrder) {
		this.sortOrder = sortOrder;
	}

	public Direction getSortOrderStr() {
		if ("desc".equals(sortOrder)) {
			return Direction.DESC;
		} else {
			return Direction.ASC;
		}
	}

}
